<?php


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_answer')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `task_id` int(10) unsigned NOT NULL COMMENT '作业id',
  `u_id` int(10) unsigned NOT NULL COMMENT '用户id',
  `answer` varchar(255) NOT NULL COMMENT '答案',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块',
  `state` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态 1待批改 2已批改',
  `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '答题状态 2正确 3错误',
  `t_answer` varchar(255) NOT NULL COMMENT '老师答案',
  `answer_time` int(4) NOT NULL COMMENT '学生答案时长',
  `t_answer_time` int(4) NOT NULL COMMENT '老师答案时长',
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//答案表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_articles')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `title` varchar(100) NOT NULL COMMENT '公告标题',
  `thumb` varchar(255) NOT NULL COMMENT '缩略图',
  `content` text NOT NULL COMMENT '内容',
  `author` varchar(20) NOT NULL COMMENT '作者',
  `uniacid` int(10) unsigned NOT NULL COMMENT '所属模块',
  `state` tinyint(1) unsigned NOT NULL COMMENT '1 为正常 2为头条',
  `create_time` datetime NOT NULL COMMENT '创建时间'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//公告表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_class')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `cou_id` int(10) unsigned NOT NULL COMMENT '课程id',
  `class_name` varchar(30) NOT NULL COMMENT '课程标题',
  `sort` tinyint(1) unsigned NOT NULL COMMENT '排序',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//班级表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_course')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `c_id` int(10) unsigned NOT NULL COMMENT '课程分类id',
  `name` varchar(30) NOT NULL COMMENT '课程标题',
  `sort` tinyint(1) unsigned NOT NULL COMMENT '排序',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//课程表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_coursecate')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `school_id` int(10) unsigned NOT NULL COMMENT '校区id',
  `course_name` varchar(30) NOT NULL COMMENT '课程分类名称',
  `sort` tinyint(4) unsigned NOT NULL COMMENT '分类排序',
  `state` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//学级表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_exchange')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `user_id` int(11) NOT NULL COMMENT '用户id',
  `hx_id` int(11) NOT NULL COMMENT '核销人ID(老师ID)',
  `prize_id` int(11) NOT NULL COMMENT '商品id',
  `time` varchar(20) NOT NULL COMMENT '申请时间',
  `user_name` varchar(20) NOT NULL COMMENT '用户地址',
  `user_tel` varchar(20) NOT NULL COMMENT '用户电话',
  `score` int(11) NOT NULL COMMENT '积分',
  `prize_name` varchar(50) NOT NULL COMMENT '商品名称',
  `prize_img` varchar(100) NOT NULL,
  `state` int(4) NOT NULL COMMENT '状态1待确认,2已发放',
  `dh_time` varchar(20) NOT NULL COMMENT '兑换时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_hx')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `user_id` int(11) NOT NULL COMMENT '用户id',
  `hx_id` int(11) NOT NULL COMMENT '核销人id',
  `time` datetime NOT NULL COMMENT '时间',
  `uniacid` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='核销表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_prize')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` varchar(25) NOT NULL COMMENT '奖品名称',
  `pic` varchar(255) NOT NULL COMMENT '图片',
  `num` int(10) unsigned NOT NULL COMMENT '数量',
  `need_score` decimal(10,0) unsigned NOT NULL COMMENT '所需积分',
  `description` text NOT NULL COMMENT '奖品描述',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//奖品表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_school')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `cate_name` varchar(30) NOT NULL COMMENT '校区名称',
  `address` varchar(255) NOT NULL COMMENT '校区地址',
  `phone` varchar(11) NOT NULL COMMENT '校区电话',
  `state` tinyint(1) unsigned NOT NULL COMMENT '1为新用户 2为正常校区',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//校区表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_scoredetails')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `task_id` int(10) unsigned NOT NULL COMMENT '作业id',
  `prize_id` int(11) NOT NULL COMMENT '奖品ID',
  `u_id` int(10) unsigned NOT NULL COMMENT '用户id',
  `type` int(4) NOT NULL DEFAULT '1' COMMENT '1加,2减',
  `score` decimal(10,2) unsigned NOT NULL COMMENT '积分',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//积分详情';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_slide')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `sort` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '幻灯片排序',
  `name` varchar(100) NOT NULL COMMENT '幻灯片标题',
  `thumb` varchar(255) NOT NULL COMMENT '缩略图',
  `description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '幻灯片描述',
  `link` varchar(255) NOT NULL COMMENT '幻灯片链接',
  `status` tinyint(1) unsigned NOT NULL COMMENT '状态 0为禁用 1为启用',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(50) NOT NULL COMMENT '所属公众号'
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//幻灯片表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_smsconfig')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL COMMENT '用户id',
  `appkey` varchar(100) NOT NULL COMMENT '短信接口appkey',
  `tpl_id` varchar(50) NOT NULL COMMENT '短信模板id ',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//手机短信配置表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_students')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `class_id` int(10) unsigned NOT NULL COMMENT '班级id',
  `name` varchar(20) NOT NULL COMMENT '学生姓名',
  `sex` tinyint(1) unsigned NOT NULL COMMENT '性别 1男 2女',
  `birthday` datetime NOT NULL COMMENT '生日',
  `score` decimal(10,2) unsigned NOT NULL COMMENT '积分',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(20) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='//学生信息表';"

);


pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_subject')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `cou_id` int(10) unsigned NOT NULL COMMENT '课程id',
  `title` varchar(100) NOT NULL COMMENT '题目的标题',
  `video` varchar(255) NOT NULL COMMENT '作业内容',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='//题目表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_system')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `appid` varchar(100) NOT NULL COMMENT 'appid',
  `appsecret` varchar(200) NOT NULL COMMENT 'appsecret',
  `mchid` varchar(20) NOT NULL COMMENT '商户号',
  `wxkey` varchar(100) NOT NULL COMMENT '商户秘钥',
  `uniacid` varchar(50) NOT NULL,
  `url_name` varchar(20) NOT NULL COMMENT '网址名称',
  `details` text NOT NULL COMMENT '关于我们',
  `url_logo` varchar(100) NOT NULL COMMENT '网址logo',
  `bq_name` varchar(50) NOT NULL COMMENT '版权名称',
  `link_name` varchar(30) NOT NULL COMMENT '网站名称',
  `link_logo` varchar(100) NOT NULL COMMENT '网站logo',
  `support` varchar(20) NOT NULL COMMENT '技术支持',
  `bq_logo` varchar(100) NOT NULL,
  `color` varchar(20) NOT NULL,
  `tz_appid` varchar(30) NOT NULL,
  `tz_name` varchar(30) NOT NULL,
  `pt_name` varchar(30) NOT NULL COMMENT '平台名称',
  `tel` varchar(20) NOT NULL COMMENT '平台电话',
  `rz_xuz` text NOT NULL COMMENT '入驻须知',
  `ft_xuz` text NOT NULL COMMENT '发帖须知',
  `total_num` int(11) NOT NULL COMMENT '访问量',
  `appkey` varchar(50) NOT NULL COMMENT '短信appkey',
  `tpl_id` varchar(20) NOT NULL COMMENT '短信模板id',
  `rc_content` text NOT NULL COMMENT '认筹规则',
  `apiclient_cert` text NOT NULL COMMENT '证书',
  `apiclient_key` text NOT NULL COMMENT '证书',
  `zd_money` decimal(10,2) unsigned NOT NULL COMMENT '最低提现金额',
  `tx_sxf` decimal(10,3) unsigned NOT NULL COMMENT '提现手续费',
  `rc_tk` text NOT NULL COMMENT '认筹条款',
  `tid1` varchar(50) NOT NULL COMMENT '报名成功通知模板id',
  `tid2` varchar(50) NOT NULL COMMENT '发布活动通知模板id',
  `tid3` varchar(50) NOT NULL COMMENT '认证通知模板id',
  `tx_notice` text NOT NULL COMMENT '提现须知',
  `style` int(4) NOT NULL DEFAULT '1' COMMENT '风格设置,1左右布局,2上下布局',
  `fwf_notice` text NOT NULL COMMENT '服务费须知',
  `tx_mode` int(4) NOT NULL COMMENT '1手动打款,2自动打款',
  `is_sfrz` int(4) NOT NULL DEFAULT '1' COMMENT '身份认证1开通,2不开通',
  `client_ip` varchar(30) NOT NULL COMMENT 'IP地址',
  `rz_notice` text NOT NULL COMMENT '认证须知',
  `fb_notice` text NOT NULL COMMENT '发布须知',
  `is_yhk` int(4) NOT NULL COMMENT '是否银行卡',
  `is_wx` int(4) NOT NULL COMMENT '是否微信支付',
  `is_zfb` int(4) NOT NULL COMMENT '是否支付宝',
  `tx_money` decimal(10,2) NOT NULL COMMENT '提现金额',
  `tx_details` text COMMENT '提现须知'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_task')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `unit_id` int(10) unsigned NOT NULL COMMENT '课节id',
  `title` varchar(100) NOT NULL COMMENT '作业标题',
  `thumb` varchar(255) NOT NULL COMMENT '缩略图',
  `video` varchar(255) NOT NULL COMMENT '视屏',
  `describe` text NOT NULL COMMENT '视屏作业描述',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='//作业表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_teacher')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `school_id` int(11) NOT NULL COMMENT '校区ID',
  `class_id` varchar(50) NOT NULL COMMENT '班级id',
  `teacher_name` varchar(20) NOT NULL COMMENT '老师的名称',
  `username` varchar(20) NOT NULL COMMENT '用户名',
  `password` varchar(50) NOT NULL COMMENT '登录密码',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `state` tinyint(1) unsigned NOT NULL COMMENT '状态 1启用 2禁用',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='//老师表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_unit')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `cour_id` int(10) unsigned NOT NULL COMMENT '课程id',
  `unit_name` varchar(30) NOT NULL COMMENT '课节名称',
  `num` int(10) unsigned NOT NULL COMMENT '数字名称',
  `sort` tinyint(1) unsigned NOT NULL COMMENT '排序',
  `state` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '1该课节下作业没做完 2该课节下作业已做完',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `uniacid` varchar(30) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='//课节表';"

);

pdo_query("CREATE TABLE IF NOT EXISTS".tablename('snx_users')."(
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `class_id` int(10) unsigned NOT NULL COMMENT '班级id',
  `openid` varchar(50) NOT NULL COMMENT '微信openid',
  `img` varchar(255) NOT NULL COMMENT '微信头像',
  `nickname` varchar(30) NOT NULL COMMENT '昵称',
  `students_name` varchar(16) NOT NULL COMMENT '学生真实姓名',
  `parents_name` varchar(16) NOT NULL COMMENT '家长姓名',
  `password` varchar(32) NOT NULL COMMENT '密码',
  `phone_number` varchar(11) NOT NULL COMMENT '手机号',
  `email` varchar(50) NOT NULL COMMENT '用户绑定邮箱',
  `score` decimal(10,2) unsigned NOT NULL COMMENT '总积分',
  `balance` decimal(10,2) unsigned NOT NULL COMMENT '余额',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `state` tinyint(1) unsigned NOT NULL COMMENT '1待审核 2已通过 3已拒绝',
  `uniacid` varchar(20) NOT NULL COMMENT '所属模块'
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='//用户表';"

);


 if (!pdo_fieldexists(tablename('snx_task'), 'voice')) {
    pdo_query("ALTER TABLE".tablename('snx_task')." ADD `voice` VARCHAR(300) NOT NULL ;");
}

 if (!pdo_fieldexists(tablename('snx_system'), 'dy_details')) {
    pdo_query("ALTER TABLE".tablename('snx_system')." ADD `dy_details` TEXT NOT NULL ;");
}

?>